/**
 * Created by Administrator on 2017/5/29.
 */
var webpack = require("webpack");
var html = require("html-webpack-plugin");
var extractTextPlugin = require('extract-text-webpack-plugin');
//nodejs的里的一个全局变量,它指向的是我们项目的根目录,入口文件的位置
module.exports ={
  devtool: "eval-source-map",
  entry: {
    index:__dirname + '/app/main.js',
    // index2:__dirname + '/app/main2.js',
  },

  output: {
    //需要打包后的文件 放置的位置
    path:__dirname +'/public',
    //打包后文件的名字
    filename:'js/bundle.js'
  },
  devServer: {
    contentBase: "./public",//本地服务器所加载的页面所在的目录
    colors: true,//终端中输出结果为彩色---没有颜色了
    // historyApiFallback: true,//不跳转
    inline: true,//实时刷新
    port:8080,
    hot:true
  },
  module: {
    loaders:[
      {
        test: /\.json$/,
        use: 'json-loader'
      },
      {
        test: /\.html$/,
        loader: "raw-loader"
      },
      {
        test: /\.css$/,
        //从右向左翻译,css-loader必须在右边,不然没办法执行style-loader
        use:[
          'style-loader', 'css-loader',
          {
          loader: "postcss-loader",
          options:{
            plugins: (loader) => [
              require('autoprefixer')
              ]
          }
        }]
      },
      {
        test: /\.js$/,
        exclude: /(node_modules|bower_components)/,
        loader: 'babel-loader',
        query: {
          presets: ['es2015']
        }
      }
    ],
    rules:[{
      test:/\.css$/,
      use:extractTextPlugin.extract({
        fallback:"style-loader",
        use:"css-loader"
      })
    }]
  },
  plugins: [
    new extractTextPlugin("css/style.css"),
    //创建一个新的页面在public 以app/index.html中的文件为依据
    new html({
      title:'有没有呢',
      filename:'index.html',
      template:__dirname + "/app/index.html",
      inject:'body',
      minify:{
        //移除属性的引号
        removeAttributeQotes:true
      },
      hash:true,
      chunks:['index'],
      xhtml:true,
      showErrors:true
    }),
    new html({
      filename:'test.html',
      template:__dirname + "/app/tpl.html",
      inject:"body"
    })
  ],

};